package main

import (
	"github.com/spf13/viper"
	"venus/apps/app"
	"venus/conf"
	"venus/core"
	"venus/servers/game/srv"
	"venus/service/sv_cmd"
	"venus/service/sv_schedule"
	"venus/service/sv_tcp"
	"venus/service/sv_ws"
	"venus/util/zredis"
)

func main() {
	if !app.Init() {
		return
	}

	if !conf.InitMapAll() {
		return
	}
	if !conf.InitExtGame() {
		return
	}

	// redis
	zredis.Init(viper.GetString("redis.addr"), viper.GetString("redis.password"), viper.GetInt("redis.db"))
	if !zredis.Check() {
		return
	}

	svCmd := sv_cmd.NewSv(srv.CmdRegister)
	core.AddSv(svCmd)

	svSchedule := sv_schedule.NewSv(srv.ScheduleRegister)
	core.AddSv(svSchedule)

	svTcp := sv_tcp.NewSv(srv.TcpConnStart, srv.TcpConnStop, srv.TcpRegister)
	core.AddSv(svTcp)

	svWs := sv_ws.NewSv(srv.WsRegister)
	core.AddSv(svWs)

	go core.StartSv()
	core.WaitTermSignal()
}
